// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-11-12

package base

import "strings"

// Level
// 日志级别, 定义日志收集等级.
type Level string

const (
	LevelDebug Level = "DEBUG"
	LevelInfo  Level = "INFO"
	LevelWarn  Level = "WARN"
	LevelError Level = "ERROR"
	LevelFatal Level = "FATAL"
)

// Defaulter
// 计算默认值.
func (o Level) Defaulter() Level {
	v := Level(strings.ToUpper(o.String()))
	switch v {
	case LevelDebug, LevelWarn, LevelError, LevelFatal:
		return v
	}
	return LevelInfo
}

// IsError
// 是否 ERROR 级日志.
func (o Level) IsError() bool { return o == LevelError }

// IsFatal
// 是否 FATAL 级日志.
func (o Level) IsFatal() bool { return o == LevelFatal }

// String
// 转成字符串.
func (o Level) String() string { return string(o) }

// +---------------------------------------------------------------------------+
// | Level status                                                              |
// +---------------------------------------------------------------------------+

func (o Level) DebugOn() bool {
	switch o {
	case LevelDebug:
		return true
	}
	return false
}

func (o Level) ErrorOn() bool {
	switch o {
	case LevelError, LevelWarn, LevelInfo, LevelDebug:
		return true
	}
	return false
}

func (o Level) FatalOn() bool {
	switch o {
	case LevelFatal, LevelError, LevelWarn, LevelInfo, LevelDebug:
		return true
	}
	return false
}

func (o Level) InfoOn() bool {
	switch o {
	case LevelInfo, LevelDebug:
		return true
	}
	return false
}

func (o Level) WarnOn() bool {
	switch o {
	case LevelWarn, LevelInfo, LevelDebug:
		return true
	}
	return false
}
